{\rtf1\ansi\deff0\adeflang1025
{\fonttbl{\f0\froman\fprq2\fcharset0 Times New Roman;}{\f1\froman\fprq2\fcharset0 Times New Roman;}{\f2\fswiss\fprq2\fcharset0 Arial;}{\f3\froman\fprq2\fcharset0 Times New Roman;}{\f4\fswiss\fprq2\fcharset128 Microsoft Sans Serif;}{\f5\fswiss\fprq2\fcharset0 Arial Unicode MS;}{\f6\fnil\fprq2\fcharset0 MS Mincho;}{\f7\fnil\fprq0\fcharset0 Tahoma;}}
{\colortbl;\red0\green0\blue0;\red128\green128\blue128;}
{\stylesheet{\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033\snext1 Normal;}
{\s2\sb240\sa120\keepn\rtlch\af2\afs28\lang255\ltrch\dbch\af6\langfe255\hich\f2\fs28\lang1033\loch\f2\fs28\lang1033\sbasedon1\snext3 Heading;}
{\s3\sa120\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033\sbasedon1\snext3 Body Text;}
{\s4\sa120\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033\sbasedon3\snext4 List;}
{\s5\sb120\sa120\rtlch\af7\afs24\lang255\ai\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\i\loch\fs24\lang1033\i\sbasedon1\snext5 caption;}
{\s6\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033\sbasedon1\snext6 Index;}
{\s7\sb120\sa120\rtlch\afs24\lang255\ai\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\i\loch\fs24\lang1033\i\sbasedon1\snext7 caption;}
}
{\info{\creatim\yr2011\mo7\dy19\hr6\min24}{\revtim\yr0\mo0\dy0\hr0\min0}{\printim\yr0\mo0\dy0\hr0\min0}{\comment StarWriter}{\vern3000}}\deftab709
{\*\pgdsctbl
{\pgdsc0\pgdscuse195\pgwsxn12240\pghsxn15840\marglsxn1134\margrsxn1134\margtsxn1134\margbsxn1134\pgdscnxt0 Standard;}}
{\*\pgdscno0}\paperh15840\paperw12240\margl1134\margr1134\margt1134\margb1134\sectd\sbknone\pgwsxn12240\pghsxn15840\marglsxn1134\margrsxn1134\margtsxn1134\margbsxn1134\ftnbj\ftnstart1\ftnrstcont\ftnnar\aenddoc\aftnrstcont\aftnstart1\aftnnrlc
\pard\plain \ltrpar\s1\ql\rtlch\af4\afs20\lang255\ltrch\dbch\af5\langfe255\hich\f4\fs20\lang1033\loch\f4\fs20\lang1033 {\rtlch \ltrch\loch\f4\fs20\lang1033\i0\b0 using Tesla.Bounding;}
\par \pard\plain \ltrpar\s1\ql\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\f4\fs20\lang1033\loch\f4\fs20\lang1033 {\rtlch \ltrch\loch\f4\fs20\lang1033\i0\b0 using Tesla.Content;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch\f4\fs20\lang1033\i0\b0 using Tesla.Core;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch\f4\fs20\lang1033\i0\b0 using Tesla.Graphics;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch\f4\fs20\lang1033\i0\b0 using Tesla.Input;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch\f4\fs20\lang1033\i0\b0 using Tesla.Math;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch\f4\fs20\lang1033\i0\b0 using Tesla.Scene;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch\f4\fs20\lang1033\i0\b0 using Tesla.Scene.Shape;}
\par \pard\plain \ltrpar\s1\ql\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 
\par \pard\plain \ltrpar\s1\ql\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\f4\fs20\lang1033\loch\f4\fs20\lang1033 {\rtlch \ltrch\loch\f4\fs20\lang1033\i0\b0 namespace TeslaSamples.Bounding \{}
\par \pard\plain \ltrpar\s1\ql\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch     }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 [AppDescription("Ray Picking", PlatformCapabilities.Direct3D10 | PlatformCapabilities.XNA4, "RayPickingImage", "RayPickingDesc", "RayPickingSource")]}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch     }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 public class RayPicking : BasicApp \{}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch         }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 private PickQuery query;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch         }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 private Mesh picks;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch         }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 private Line pickRay;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch         }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 protected override void LoadContent() \{}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 //Load a model that we'll use to pick}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 ModelLoaderParameters mlp = new ModelLoaderParameters();}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 mlp.SwapWindingOrder = true;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 mlp.NormalGeneration = NormalGeneration.Crease;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 mlp.PreferLitMaterials = true;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 Spatial jeep = ContentManager.Load<Spatial>("Models//Jeep.dxs", mlp);}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 jeep.Translation = new Vector3(0, -50, 0);}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 jeep.Rotation = Quaternion.FromAngleAxis(MathHelper.ToRadians(140), Vector3.UnitY);}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 jeep.SetModelBound(new BoundingBox());}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 RootNode.AddChild(jeep);}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 //Adjust the default camera a tad}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 Renderer.CurrentCamera.Position = new Vector3(0, 50, 100);}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 Renderer.CurrentCamera.LookAt(jeep.Translation, Vector3.Up);}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 Renderer.CurrentCamera.Update();}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 //Set the mouse visible so we can see the cursor}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 Window.IsMouseVisible = true;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 //Create our query}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 query = new PickQuery();}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 //We want to enable primitive picking to get triangle accurate results, when we do the intersection tests,}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 //the utility will first do a board bounding volume test, and if that succeeds then a finer primitive test.}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 query.EnablePrimitivePicking = true; }
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 //Setup out input - whenever we left click, we'll cast a ray into the scene}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 InputLayer.RegisterTrigger(new InputTrigger(new InputCondition(delegate(GameTime time) \{}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch                 }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 MouseState ms = Mouse.GetMouseState();}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch                 }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 if(ms.LeftButton == ButtonState.Pressed) \{}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch                     }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 return true;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch                 }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 \}}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch                 }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 return false;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 \}), new InputAction(delegate(GameTime time) \{}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch                 }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 MouseState ms = Mouse.GetMouseState();}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch                 }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 query.Clear();}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch                 }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 //The camera class has easy-built in functionality to quickly create a pick ray where the origin}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch                 }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 //of the ray is on the near-plane of the view frustum}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch                 }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 PickingUtil.FindPick(RootNode, Renderer.CurrentCamera.CreatePickRay(ms.Position), query);}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch                 }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 CreatePicks(query);}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 \})));}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch         }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 \}}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch         }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 private void CreatePicks(PickQuery query) \{}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 if(query.Count == 0) \{}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch                 }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 return;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 \}}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 query.Sort();}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 //Lazily create the mesh that holds the pick visuals, for this example we're only doing the closest picked}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 //triangle}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 if(picks == null) \{}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch                 }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 picks = new Mesh("Picks");}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch                 }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 picks.Material = ContentManager.Load<Material>("Materials//BasicColor.tem").Clone();}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch                 }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 picks.Material.SetParameter("DiffuseColor", Color.Yellow);}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch                 }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 picks.SetRenderState(RasterizerState.CullNoneWireframe);}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch                 }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 picks.SetRenderState(DepthStencilState.None);}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch                 }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 picks.MeshData.Positions = new DataBuffer<Vector3>(3);}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch                 }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 picks.MeshData.UseIndexedPrimitives = false;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch                 }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 picks.MeshData.Reconstruct();}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch                 }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 picks.SceneHints.RenderBucketType = RenderBucketType.PostBucket;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch                 }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 picks.SceneHints.PickingHint = PickingHint.None;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch                 }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 RootNode.AddChild(picks);}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch                 }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 pickRay = new Line("PickRay");}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch                 }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 pickRay.Material = ContentManager.Load<Material>("Materials//BasicVertColor.tem").Clone();}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch                 }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 RootNode.AddChild(pickRay);}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 \}}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 DataBuffer<Vector3> db = picks.MeshData.Positions;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 db.Position = 0;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 PickResult results = query.ClosestPick.Value;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 Ray ray = results.SourceRay;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 //Get the closest primitive intersection record, and the closest intersection triangle (a ray may pass through many}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 //triangles, we want the one closest to the ray's origin). These should exist, if we have results.}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 IntersectionRecord record = results.PrimitiveIntersectionRecord.Value.ClosestIntersection.Value;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 Triangle tri = record.Triangle.Value;}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 db.Set(tri.PointA);}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 db.Set(tri.PointB);}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 db.Set(tri.PointC);}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 //Set the pick ray so we can see it on the screen}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 pickRay.SetLine(ray.Origin, ray.Origin + ray.Direction * (record.Distance + 100), Color.Orange, Color.Orange);}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 //Update the pick result with the triangle data}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch             }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 picks.MeshData.UpdateVertexData<Vector3>(VertexSemantic.Position, db);}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch         }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 \}}
\par \pard\plain \ltrpar\s1\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\fs24\lang1033\loch\fs24\lang1033 {\rtlch \ltrch\loch     }{\rtlch \ltrch\loch\f0\fs24\lang1033\i0\b0\ltrch\hich\f4\fs20\loch\f4\fs20 \}}
\par \pard\plain \ltrpar\s1\ql\rtlch\afs24\lang255\ltrch\dbch\af5\langfe255\hich\f4\fs20\lang1033\loch\f4\fs20\lang1033 {\rtlch \ltrch\loch\f4\fs20\lang1033\i0\b0 \}}
\par }